package com.fintech.third.service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.annotation.Resource;

import org.springframework.context.ApplicationContext;

import com.fintech.third.dao.ThirdRequestResponseMapper;
import com.fintech.third.model.ThirdRequest;
import com.fintech.third.model.ThirdResponse;
import com.fintech.third.utils.ApplicationContextGet;
import com.marvels.common.utils.MarvelsLogUtil;

/**
 * 第三方接口日志数据处理
 * 
 * @author tangpw
 *
 */
public class ThirdDataDeal {
	@Resource(name="thirdRequestResponseMapper")
	private ThirdRequestResponseMapper thirdRequestResponseMapper;

	private ApplicationContext ac =ApplicationContextGet.getApplicationContext();
	/**
	 * 第三方请求数据处理
	 * 
	 * @param order_number
	 * @param request_type
	 * @param return_content
	 */
	public void dealThirdRequestData(String channelCode,String requestNo,String orderNumber, String requestType, String requestContent,String interfaceCode) {
		
		thirdRequestResponseMapper = (ThirdRequestResponseMapper) ac.getBean("thirdRequestResponseMapper");
		ThirdRequest thirdRequest = new ThirdRequest();
		thirdRequest.setRequestNo(requestNo);
		thirdRequest.setOrderNumber(orderNumber);
		thirdRequest.setRequestContent(requestContent);
		thirdRequest.setRequestType(requestType);
		thirdRequest.setChannelCode(channelCode);
		thirdRequest.setInterfaceCode(interfaceCode);
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		try {
			thirdRequest.setRequestTime(simpleDateFormat.parse(simpleDateFormat.format(new Date())));
		} catch (ParseException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		try {
			thirdRequestResponseMapper.addThirdRequestInfo(thirdRequest);
		} catch (Exception e) {
			e.printStackTrace();
			MarvelsLogUtil.getInstance().info("===============>>保存第三方请求数据异常:" + e.getMessage());
		}
	}

	/**
	 * 第三方返回数据处理
	 * 
	 * @param order_number
	 * @param return_content
	 */
	public void dealThirdResponseData(String channelCode,String returnNo,String orderNumber, String type, String returnContent,String interfaceCode) {
		ThirdResponse thirdResponse = new ThirdResponse();
		thirdResponse.setOrderNumber(orderNumber);
		thirdResponse.setReturnNo(returnNo);
		thirdResponse.setReturnContent(returnContent);
		thirdResponse.setType(type);
		thirdResponse.setChannelCode(channelCode);
		thirdResponse.setInterfaceCode(interfaceCode);
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		try {
			
			thirdResponse.setReturnTime(simpleDateFormat.parse(simpleDateFormat.format(new Date())));
		} catch (ParseException e1) {
			e1.printStackTrace();
		}
		try {
			thirdRequestResponseMapper.addThirdResponseInfo(thirdResponse);
		} catch (Exception e) {
			e.printStackTrace();
			MarvelsLogUtil.getInstance().info("===============>>保存第三方返回数据异常:" + e.getMessage());
		}
	}

}
